package com.whfc.ms.api.base.service.impl;

import com.whfc.common.exception.BizException;
import com.whfc.common.result.PageData;
import com.whfc.common.result.ResultEnum;
import com.whfc.emp.service.AppEmpService;
import com.whfc.fuum.dto.AppCorpDTO;
import com.whfc.fuum.param.AppCorpAddParam;
import com.whfc.fuum.param.AppCorpEditParam;
import com.whfc.fuum.param.AppCorpListQO;
import com.whfc.fuum.service.AppCorpService;
import com.whfc.ms.api.base.service.MsAppCorpService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author qzexing
 * @version 1.0
 * @date 2020-12-10 19:45
 */
@Service
public class MsAppCorpServiceImpl implements MsAppCorpService {

    @DubboReference(interfaceClass = AppCorpService.class, version = "1.0.0")
    private AppCorpService appCorpService;

    @DubboReference(interfaceClass = AppEmpService.class, version = "1.0.0")
    private AppEmpService appEmpService;

    @Override
    public List<AppCorpDTO> getCorpList(Integer deptId) {
        return appCorpService.list(deptId);
    }

    @Override
    public PageData<AppCorpDTO> list(AppCorpListQO request) {
        return appCorpService.list(request);
    }

    @Override
    public AppCorpDTO detail(Integer corpId) {
        return appCorpService.detail(corpId);
    }

    @Override
    public void add(AppCorpAddParam request) {
        appCorpService.add(request);
    }

    @Override
    public void edit(AppCorpEditParam request) {
        appCorpService.edit(request);
    }

    @Override
    public void del(Integer corpId) {
        //判断该合作公司下是否有员工
        Integer empCount = appEmpService.countEmpByCorpId(corpId);
        if (empCount > 0) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "该合作公司下有员工在岗，不能删除！");
        }
        appCorpService.del(corpId);
    }
}
